home *** CD-ROM | disk | FTP | other *** search
- Path: unixg.ubc.ca!news
- From: jamesdf@unixg.ubc.ca (James Fairweather)
- Newsgroups: comp.lang.c++
- Subject: Pointer to non-static function
- Date: Thu, 07 Mar 1996 23:49:16 GMT
- Organization: Resnet
- Message-ID: <4hnsfs$cp2@nntp.ucs.ubc.ca>
- NNTP-Posting-Host: srtb0411a01.resnet.ubc.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- I am attempting to make some code I've written more elegant by using a
- pointer to a function. Here's how I declare the pointer:
-
- double (*f)(double);
-
- Now I'd like to make f point to one of two functions, one declared as:
-
- double CFunction::Calculate(double);
-
- and the other as:
-
- double CEquation::Calculate(double);
-
- Neither are static, and CEquation and CFunction are not related by
- inheritance. Nor can they be, since CEquation contains a list of
- CFunctions.
-
- At compile time, the compiler issues an error, "cannot convert from
- double (CFunction::*)(double) to double (__cdecl *)(double)" and
- "cannot convert from double (CEquation::*)(double) to double (__cdecl
- *)(double)".
-
- This looks suspiciously like a typecasting problem to me. I'm
- wondering if what I'm attempting to do is possible, and if so, how to
- do it. What is the correct way to do the typecast, if that is the
- problem? Any help is much appreciated.
-
- James
-
-
-